package com.example.yiwei.crm.view.activity.JYCoordingActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.TimePickerView;
import com.example.yiwei.crm.R;
import com.example.yiwei.crm.entity.BMEntity;
import com.example.yiwei.crm.view.activity.jtCustomer.JDcoorActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class JYSearchCoordingActivity extends AppCompatActivity {
    private EditText edit_name,edit_jg,edit_bm,edit_pnm,edit_cid,edit_manger;
    private ArrayAdapter fzadaper,bmadaper;
    private SharedPreferences sp;
    List<BMEntity> fzlist;
    List<BMEntity> abmlist;

    String fzbianma = null;
    private ImageView img_update;
    String bmbianma = null;
    LinearLayout linearLayout;
    private ImageView img_luru,img_search,img_tj,img_me,img_back;
    private TimePickerView mpv1;
    private TimePickerView mpv2;
    Date date1,date2,date3,date4;
    String stime;
    String etime;
    TextView stimetv,etimetv;
    private Button btn1,btn2;
    private ImageView img_qk,img_qk1;
    private Button btn_commit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jysearch_coording);
        btn_commit = (Button) findViewById(R.id.btn_commit);
        img_qk= (ImageView) findViewById(R.id.qingkong);
        img_qk1= (ImageView) findViewById(R.id.qingkong1);
        stimetv = (TextView) findViewById(R.id.start_time);
        etimetv = (TextView) findViewById(R.id.end_time);
        btn1= (Button) findViewById(R.id.start_show);
        btn2= (Button) findViewById(R.id.end_show);
        edit_name = (EditText) findViewById(R.id.health_education_add_edit_docking_name);
        img_back= (ImageView) findViewById(R.id.detailed_doc_img_back);
        edit_jg = (EditText) findViewById(R.id.health_education_add_edit_docking_jg);
        edit_bm = (EditText) findViewById(R.id.health_education_add_edit_docking_bm);
        edit_pnm = (EditText) findViewById(R.id.health_education_add_edit_docking_pnm);
        edit_cid = (EditText) findViewById(R.id.health_education_add_edit_docking_cname);
        img_update= (ImageView) findViewById(R.id.detailed_doc_img_update);
        linearLayout= (LinearLayout) findViewById(R.id.search_linearLayout);
        edit_manger = (EditText) findViewById(R.id.health_education_add_edit_docking_manger);
        img_luru= (ImageView) findViewById(R.id.item_image_lr);
        img_search= (ImageView) findViewById(R.id.item_image_cx);
        img_me= (ImageView) findViewById(R.id.item_image_w);
        img_tj= (ImageView) findViewById(R.id.item_image_tj);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
            img_back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            img_tj.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchCoordingActivity.this, JDcoorActivity.class);
                    intent.putExtra("tt","tt");
                    startActivity(intent);
                    finish();

                }
            });
            img_me.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchCoordingActivity.this, JDcoorActivity.class);
                    intent.putExtra("me","me");
                    startActivity(intent);
                    finish();
                }
            });
            img_luru.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchCoordingActivity.this, JDcoorActivity.class);
                    startActivity(intent);
                    finish();
                }
            });
            img_search.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchCoordingActivity.this, JDcoorActivity.class);
                    intent.putExtra("ii","ii");
                    startActivity(intent);
                    finish();
                }
            });
        //创建选择器
        mpv1 = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar = Calendar.getInstance();
        mpv1.setRange(calendar.get(Calendar.YEAR) - 100, calendar.get(Calendar.YEAR) + 100);
        //插入时间
        mpv1.setTime(new Date());
        //选择监听
        mpv1.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date1 = date;
                stime=getTime(date);
                stimetv.setText(stime);
            }
        });
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mpv1.show();
            }
        });
        mpv2 = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar1 = Calendar.getInstance();
        mpv2.setRange(calendar1.get(Calendar.YEAR) - 100, calendar1.get(Calendar.YEAR) + 100);
        //插入时间
        mpv2.setTime(new Date());
        //选择监听
        mpv2.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date2 = date;
                etime=getTime(date);
                etimetv.setText(etime);
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mpv2.show();
            }
        });
        img_qk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                stimetv.setText("");
            }
        });
        img_qk1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                etimetv.setText("");
            }
        });
        btn_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(JYSearchCoordingActivity.this, SimpleCoordingActivity1.class);
                intent.putExtra("tag1", "k1");
                intent.putExtra("KXA02", edit_name.getText().toString());
                intent.putExtra("KXA03", edit_jg.getText().toString());
                intent.putExtra("KXA05", edit_bm.getText().toString());
                intent.putExtra("KXA08", edit_pnm.getText().toString());
                intent.putExtra("KXA15", edit_manger.getText().toString());
                intent.putExtra("CID03", edit_cid.getText().toString());
                intent.putExtra("CTS01A",stime);
                intent.putExtra("CTS01B",etime);
                startActivity(intent);
                finish();

            }

        });
    }
    public static String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }
}
